package com.xk857.simpleeffect.activity;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.xk857.simpleeffect.R;
import com.xk857.simpleeffect.adapter.TabViewPagerAdapter;
import com.xk857.simpleeffect.domain.entity.Project;
import com.xk857.simpleeffect.fragment.project.ProjectInfoFragment;
import com.xk857.simpleeffect.fragment.project.ProjectNoFragment;
import com.xk857.simpleeffect.fragment.project.ProjectYesFragment;
import com.xuexiang.xui.widget.actionbar.TitleBar;
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog;

public class UpdateProjectActivity extends AppCompatActivity {

    private TitleBar titleBar;
    private TabLayout tabLayout;
    //    private ViewPager viewPager;
    private ViewPager2 pager;
    private Project project;

    private final Fragment[] fragmentList = new Fragment[3];
    private final String[] tabItems = {"概览", "未完成", "已完成"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.main_bg));
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        setContentView(R.layout.activity_update_project);
        initView();
    }

    private void initView() {
        int projectId = getIntent().getIntExtra("projectId", -1);
        String projectName = getIntent().getStringExtra("projectName");
        if (projectId == -1) {
            new MaterialDialog.Builder(this).iconRes(R.drawable.icon_info).title(R.string.info).content("请传递id到此页面").positiveText(R.string.yes).onPositive((dialog, which) -> finish()).show();
        }
        titleBar = findViewById(R.id.title_bar);
        titleBar.setTitle(projectName);
        tabLayout = findViewById(R.id.tabLayout);
        pager = findViewById(R.id.view_pager2);
        titleBar.setLeftClickListener(view -> finish());
        fragmentList[0] = ProjectInfoFragment.newInstance(projectId);
        fragmentList[1] = ProjectNoFragment.newInstance(projectId);
        fragmentList[2] = ProjectYesFragment.newInstance(projectId);
        pager.setAdapter(new TabViewPagerAdapter(this, fragmentList));
        // 将tabLayout和ViewPager相互绑定
        new TabLayoutMediator(tabLayout, pager, (tab, position) -> tab.setText(tabItems[position])).attach();
    }


}